package com.zlj.ajax.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/AjaxServlet")
public class AjaxServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Hello ajax!");
        response.getWriter().println("Hello Ajax!");
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");  //处理请求编码
		response.setContentType("text/html;charset=utf-8");  //处理响应编码
		String username = request.getParameter("username");  //获取请求参数
		String password = request.getParameter("password");  //获取请求参数
        System.out.println("Hello ajax!(POST方法)" + "--" + password);
        response.getWriter().println("Hello Ajax!(POST方法)" + "---" + username);
	}
}
